package com.ciei.dpagm.util;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;
import java.util.List;

/**
 * 树节点类
 * 根据Element-UI Tree控件的数据格式构建
 *
 * @author fangnuozhou
 * @date 2020/08/20
 */
public class TreeNode implements Comparable<TreeNode> {
    /**
     * ID
     */
    private Integer id;
    /**
     * 父ID
     */
    @JSONField(serialize = false)
    private Integer pid;
    /**
     * 显示内容
     */
    private String label;
    /**
     * 顺序
     */
    @JSONField(serialize = false)
    private int order = 0;
    /**
     * 子节点
     */
    private List<TreeNode> children = new ArrayList<>();

    public TreeNode(Integer id, Integer pid) {
        this.id = id;
        this.pid = pid;
    }

    public TreeNode(Integer id, Integer pid, String label) {
        this(id, pid);
        this.label = label;
    }

    public TreeNode(Integer id, Integer pid, String label, int order) {
        this(id, pid);
        this.label = label;
        this.order = order;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children == null ? new ArrayList<>() : children;
    }

    @Override
    public int compareTo(TreeNode node) {
        return this.order - node.order;
    }
}
